package org.wattdepot.cli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the ListSensorDataDay class.
 * 
 * @author Yichi Xu
 *
 */
public class TestDailySensorDataCommand extends CommandTestBed {
  /** 
   * Tests the doCommand method of ListSensorDataDayCommand.
   * 
   * @see org.wattdepot.cli.command.CommandTestBed#testDoCommand()
   */
  @Test
  @Override
  public void testDoCommand() {
    String command;
    String result;
    
    DailySensorDataCommand listCommand = new DailySensorDataCommand(this.client);
    
    //Sad tests
    //Correct input "dailysensordata SIM_KAHE_1 day 2009-11-01"
    command = "dailysensordata SIM_KAHE_1 foo 2009-11-01";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the day parameter is invalid.", 
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));
    
    command = "dailysensordata SIM_KAHE_1 day 2009-11-01 foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking invalid number of parameters.", 
        result.startsWith(WattDepotCliCommand.PARAMETER_COUNT_ERROR));
    
    command = "dailysensordata foo day 2009-11-01";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the source is invalid.", 
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
    
    command = "dailysensordata SIM_KAHE_1 day foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the timestamp is invalid.", 
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    
    //Happy tests
    command = "dailysensordata SIM_KAHE_1 day 2009-11-01";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a result for the query",
        result.contains("Total"));
    assertFalse("Checking that the command is valid.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the connection is fine.",
        result.equals(WattDepotCliCommand.CONNECTION_ERROR));
    assertFalse("Checking that the day converts to timestamp correctly.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    assertFalse("Checking that the source is invalid.", 
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
  }
}
